package com.example.demo.demos.prompt;

import io.modelcontextprotocol.server.McpServerFeatures;
import io.modelcontextprotocol.spec.McpSchema;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

@Configuration
public class GreetingPrompt {
    @Bean
    public List<McpServerFeatures.AsyncPromptSpecification> myPrompts() {
        McpSchema.Prompt prompt = new McpSchema.Prompt("greeting", "A friendly greeting prompt",
                Arrays.asList(new McpSchema.PromptArgument("name", "The name to greet", true)));

        McpServerFeatures.AsyncPromptSpecification promptSpecification = new McpServerFeatures.AsyncPromptSpecification(prompt, (exchange, getPromptRequest) -> {
            String nameArgument = (String) getPromptRequest.arguments().get("name");
            if (nameArgument == null) {
                nameArgument = "friend";
            }
            McpSchema.PromptMessage userMessage = new McpSchema.PromptMessage(McpSchema.Role.USER, new McpSchema.TextContent("Hello " + nameArgument + "! How can I assist you today?"));
            McpSchema.GetPromptResult r = new McpSchema.GetPromptResult("A personalized greeting message", Arrays.asList(userMessage));
            return Mono.just(r);
        });

        return Arrays.asList(promptSpecification);
    }
}
